<?php

namespace common\models\minisite;

use Yii;

/**
 * This is the model class for table "d_mini.t_activity_show_feel".
 *
 * @property integer $id
 * @property integer $as_id
 * @property integer $c_channel 回复, 评论, 或者其它活动
 * @property integer $c_category
 * @property string $c_name
 * @property string $c_content
 * @property string $c_image
 * @property integer $c_status
 * @property integer $c_score
 * @property integer $uid
 * @property string $db_time
 * @property integer $op_id
 * @property string $c_date
 */
class MActivityShowFeel extends \yii\db\ActiveRecord
{

    public static $_STATUS_SUCCESS = 1;
    public static $_STATUS_FAIL = 2;
    public static $_STATUS_DEFAULT = 0;

    public static $STATUS = [0 => '未审核', 1 => '通过', 2 => '未通过'];
    public static $CHANNEL = [0 => '全部', 1 => '回复', 2 => '评论'];
    public static $CATEGORY = [0=> '小试最爱', 1 => '试爱美', 2 => '试元气', 3 => '试型动', 4 => '试未来',];
    //public $category = []
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'd_mini.t_activity_show_feel';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['as_id', 'c_category', 'c_status', 'uid', 'op_id', 'c_score', 'c_channel'], 'integer'],
            [['db_time', 'c_date'], 'safe'],
            [['c_name'], 'string', 'max' => 20],
            [['c_image'], 'string', 'max' => 30],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'as_id' => '活动',
            'c_category' => '类型',
            'c_name' => '商品',
            'c_content' => '详情',
            'c_image' => '图片',
            'c_status' => '状态',
            'c_score' => '评分',
            'c_channel' => '频道',
            'uid' => 'UID',
            'db_time' => '提交时间',
            'op_id' => '管理员',
            'c_date'=>'日期'
        ];
    }

    /**
     * @inheritdoc
     * @return \services\models\minisite\TActivityShowFeelQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new \services\models\minisite\TActivityShowFeelQuery(get_called_class());
    }

    public function beforeSave($insert)
    {
        if($insert){
            $this->db_time = date("Y-m-d H:i:s");
            $this->c_date = date("Y-m-d");
        }
        return parent::beforeSave($insert);
    }

    public function afterSave($insert, $changedAttributes)
    {
        parent::afterSave($insert, $changedAttributes);
        if (parent::beforeSave($insert)) {
            if ($insert) {
                $static = new MActivityShowFeelStatistics();
                $static->asf_id = $this->id;
                $static->c_view_times = 0;
                $static->c_good_times = 0;
                $static->save();
            }
        }
    }


    public function getMActivityShow()
    {
        return $this->hasOne(MActivityShow::className(), ['id'=>'as_id']);
    }

    public function getStatusStr()
    {
        return static::$STATUS[(int)$this->c_status];

    }


}
